﻿using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.IO;

namespace PlanningGIS.Engine.Controls
{
    /// <summary>
    /// 作用：空间数据相应图标
    /// </summary>
    public static class ImageUtility
    {
        /// <summary>
        /// 桌面
        /// </summary>
        public const string desktop = "Desktop";

        /// <summary>
        /// 驱动器
        /// </summary>
        public const string drive = "Drive";

        /// <summary>
        /// DVD
        /// </summary>
        public const string dvd = "Dvd";

        /// <summary>
        /// 网络磁盘
        /// </summary>
        public const string networkdrive = "NetworkDrive";

        /// <summary>
        /// 可移动存储设备
        /// </summary>
        public const string removabledrive = "RemovableDrive";

        /// <summary>
        /// 关闭时的文件夹
        /// </summary>
        public const string folderclosed = "FolderClosed";

        /// <summary>
        /// 打开时的文件夹
        /// </summary>
        public const string folderopen = "FolderOpen";

        /// <summary>
        /// GDB
        /// </summary>
        public const string gdb = "Gdb";

        /// <summary>
        /// MDB
        /// </summary>
        public const string mdb = "Mdb";
        /// <summary>
        /// 数据集
        /// </summary>
        public const string dataset = "Dataset";

        /// <summary>
        /// 图层
        /// </summary>
        public const string layer = "Layer";

        /// <summary>
        /// 注记
        /// </summary>
        public const string anno = "Anno";

        /// <summary>
        /// 点
        /// </summary>
        public const string point = "Point";

        /// <summary>
        /// 线
        /// </summary>
        public const string polyline = "Polyline";

        /// <summary>
        /// 面
        /// </summary>
        public const string polygon = "Polygon";

        /// <summary>
        /// 多路径
        /// </summary>
        public const string multipatch = "Multipatch";

        /// <summary>
        /// shp点
        /// </summary>
        public const string point_shp = "Point_shp";

        /// <summary>
        /// shp线
        /// </summary>
        public const string polyline_shp = "Polyline_shp";

        /// <summary>
        /// shp面
        /// </summary>
        public const string polygon_shp = "Polygon_shp";

        /// <summary>
        /// shp多路径
        /// </summary>
        public const string multipatch_shp = "Multipatch_shp";

        /// <summary>
        /// 数据库
        /// </summary>
        public const string database = "Database";

        /// <summary>
        /// sde连接
        /// </summary>
        public const string sdeconnect = "SdeConnect";

        /// <summary>
        /// sde断开连接
        /// </summary>
        public const string sdediscon = "SdeDisCon";

        /// <summary>
        /// 栅格数据
        /// </summary>
        public const string rastercatalog = "RasterCatalog";

        /// <summary>
        /// 栅格数据集
        /// </summary>
        public const string rasterdataset = "RasterDataset";

        /// <summary>
        /// 图片
        /// </summary>
        public const string image = "Image";

        /// <summary>
        /// DWG
        /// </summary>
        public const string dwg = "Dwg";

        /// <summary>
        /// DXF
        /// </summary>
        public const string dgn = "Dgn";

        /// <summary>
        /// 预览
        /// </summary>
        public const string preview = "Preview";

        /// <summary>
        /// 
        /// </summary>
        public const string tableset = "table";

        /// <summary>
        /// 
        /// </summary>
        public const string table = "subtable";

        /// <summary>
        /// 图片列表
        /// </summary>
        private static ImageList imageList;

        /// <summary>
        /// 静态构造函数
        /// </summary>
        static ImageUtility()
        {
            imageList = new ImageList();
            Type type = typeof(ImageUtility);
            FieldInfo[] fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Static);
            if (fieldInfos == null || fieldInfos.Length == 0) return;
            Assembly assembly = Assembly.GetAssembly(typeof(ImageUtility));
            string assemblyName = assembly.GetName().Name;
            for (int i = 0; i < fieldInfos.Length; i++)
            {
                FieldInfo fieldInfo = fieldInfos[i];
                object obj = fieldInfos[i].GetValue(null);
                if (obj == null || string.IsNullOrEmpty(obj.ToString())) continue;
                string value = obj.ToString().Trim();
                string name = assemblyName + ".Resources." + value + ".png";
                Stream stream = assembly.GetManifestResourceStream(name);
                if (stream == null) continue;
                imageList.Images.Add(value, Image.FromStream(stream));
            }
        }

        /// <summary>
        /// 获取图片列表
        /// </summary>
        /// <returns></returns>
        public static ImageList GetImageList()
        {
            return imageList;
        }

    }
}
